<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/css/base.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/font/font-awesome-4.7.0/css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/wx/css/tool-check.css" />
    <script src="/public/static/wx/js/flex.js" type="text/javascript" charset="utf-8"></script>
    <title>已选工具</title>
    <style>
        .layui-layer-btn a{
            font-size: 18px;
        }
        .layui-layer-content{
            font-size: 17px;
        }
    </style>
</head>

<body>
<div class="index">
    <div class="topbar">
        <a href="javascript:history.go(-1);"><i class="fa fa-angle-left"></i></a>
        <p>已选工具</p>
    </div>
    <div class="order-list">
        <div class="order-box clearfix">
            <div class="title-box clearfix">
                <p class="title">{:input('title')}</p>
                <span></span>
                <p class="time">{:input('time')}</p>

            </div>
            <div class="content-box clearfix">
                <div class="fix"></div>
                <div class="word-box">
                    <p class="kind-title">故障类型：<i class="kind-des">{:input('fault_name')}</i></p>
                </div>
            </div>
        </div>
    </div>

    <div class="btn" onclick="add()">添加</div>

    <div class="state mytools" id="meList">
        <!--<div class="clearfix">
            <img src="/public/static/wx/img/get-tool/1.png" alt="" />
            <div class="content">
                <p>世达（SATA）12件</p>
                <i>DY06503 工具箱套装</i>
            </div>

            <span class="remove">移除</span>
        </div>-->

    </div>


    <div id="otherList">
        <!--<div class="state">
            <p>隔壁老王</p>
            <div class="clearfix">
                <img src="/public/static/wx/img/get-tool/1.png" alt="" />
                <div class="content">
                    <p>世达（SATA）12件</p>
                    <i>DY06503 工具箱套装</i>
                </div>
            </div>
            <div class="clearfix">
                <img src="/public/static/wx/img/get-tool/1.png" alt="" />
                <div class="content">
                    <p>世达（SATA）12件</p>
                    <i>DY06503 工具箱套装</i>
                </div>
            </div>
            <div class="clearfix">
                <img src="/public/static/wx/img/get-tool/1.png" alt="" />
                <div class="content">
                    <p>世达（SATA）12件</p>
                    <i>DY06503 工具箱套装</i>
                </div>
            </div>
        </div>-->

    </div>

</div>
<script src="/public/static/wx/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/public/static/wx/plug-in/layui/layui.all.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    $('.remove').on('click',function(){
        $(this).parents('.clearfix').remove();
        checkMytool();
    });


    var ste = '{:input("ste")}';


    if(ste=='24'){
        $('.btn').hide();
    }

    function checkMytool(){
        if($('.mytools .clearfix').length == 0){
            $('.mytools').remove();
        }
    }

    var id = '{:input("id")}';

    function add() {
        location.href = '{:url("addToolsUI")}?id='+id;
    }

    var indexl = layer.load(0,{offset:['45%','45%']});
    $.post('{:url("toolsed")}',{id:id},function (data) {
        layer.close(indexl);

        if(data.data.me.data.length<=0){
            $('#meList').html('<div style="text-align: center;font-size: 16px;color: #999;background-color: #fff;">你没有选择任何工具</div>');
        }

        $.each(data.data.me.data,function (k,v) {
            $('#meList').append('<div class="clearfix">\n' +
                '            <img src="'+(v.pic&&v.pic.length>0?v.pic:'/public/static/common/images/tools-def.jpg')+'" alt="" />\n' +
                '            <div class="content">\n' +
                '                <p>'+v.title+'</p>\n' +
                '                <i>'+v.model+'</i>\n' +
                '            </div>\n' +
                '            <span class="remove" style="display:'+(ste=='24'?'none':'block')+';" onclick="rem('+v.id+')">移除</span>\n' +
                '        </div>');
        });


        if(data.data.other.length>0){

            $.each(data.data.other,function (k,v) {
                var sd = $('<div class="state"></div>');
                sd.append('<p>'+v.name+'</p>');

                $.each(v.data,function (kl,vl) {
                    sd.append('<div class="clearfix">\n' +
                        '            <img src="'+(vl.pic&&vl.pic.length>0?vl.pic:'/public/static/common/images/tools-def.jpg')+'" alt="" />\n' +
                        '            <div class="content">\n' +
                        '                <p>'+vl.title+'</p>\n' +
                        '                <i>'+vl.model+'</i>\n' +
                        '            </div>\n' +
                        '        </div>');
                });

                $('#otherList').html(sd);

            });

        }else{
            $('#otherList').html('<div class="state" style="text-align: center;font-size: 16px;color: #999">其他人没有选中工具</div>');
        }


    });


    function rem(tid) {
        layer.confirm('确认移除吗?', {icon: 3, title:'提示',shadeClose:true}, function(index){

            $.post('{:url("removeTools")}',{did:id,tid:tid},function (res) {
                if(res.code==1){
                    layer.msg(res.msg,{icon:6,shade:0.1},function () {
                        location.href = location.href+"&t";
                    });
                }else{
                    layer.msg(res.msg,{icon:5});
                }
            });

            layer.close(index);
        });
    }

</script>
</body>

</html>